import os
import os.path as osp
import numpy as np


def check_score(name, data_root, txt_path):
    # files = os.listdir(data_root)
    files = [line.strip('\n') for line in open(txt_path, 'r').readlines()]
    for f in files:
        file_path = osp.join(data_root, f + '.txt')
        lines = [line.strip('\n') for line in open(file_path).readlines()]
        lines = [line.split() for line in lines]
        names = [line[0] for line in lines]
        scores = [line[-1] for line in lines]
        if name in names:
            idx = np.argwhere(np.array(names) == name).reshape(-1)
            score_idx = np.array(scores)[idx]
            print(f)
            print(score_idx)
            

if __name__ == "__main__":
    data_root = "/cv/lyh/models/stereo-dsgn2/data/ww/training/label_2"
    txt_path = "/cv/lyh/models/stereo-dsgn2/data/ww/ImageSets/val.txt"
    check_score('pedestrian', data_root, txt_path)